#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__ = "tingfeng"

#封装 从配置文件获取element参数
import configparser

# read_ini = configparser.ConfigParser()
# data = read_ini.read('D:/Pycharm/Project/appium/config/LocalElement.ini')
# print(read_ini.get('home_element','washcar'))
#
# print('洗车')

class Read_Ini:
    #定义构建化参数 file_path可默认不传
    def __init__(self,file_path=None):
        if file_path == None:
            self.file_path = '../config/LocalElement.ini'
        else:
            self.file_path = file_path
        # 直接定义
        self.data = self.read_ini()

    def read_ini(selfi):
        read_ini = configparser.ConfigParser()
        read_ini.read('../config/LocalElement.ini',encoding= 'utf-8')
        return read_ini

    # 通过参数key获取对应的value
    #section = ['home_element']
    #key = washcar
    def get_value(self,key,section=None):
        if section == None:
            section = 'home_element'
        try:
            value = self.data.get(section,key)
            return value
        except:
            value = None
        return value

if __name__ == '__main__':
    read_ini = Read_Ini()
    print(read_ini.get_value("washcar","home_element"))